'use client'

import { useSearchParams } from 'next/navigation'
import { Fragment } from 'react';

export default function SidebarNoteList({ notes }:{
  notes: any[]
}) {
  const searchParams = useSearchParams()
  const searchText = searchParams.get('q')
  return (
    <ul className="notes-list">
      {
        notes?.map((noteItems:any)=>{
          const { noteId, note, title } = noteItems;
          if (!searchText || (searchText && title?.toLowerCase().includes(searchText.toLowerCase()))) {
            return (
              <Fragment key={noteId}>{note}</Fragment>
            )
          }

          return null
        })
      }
     
    </ul>
  )
}

